package com.bocai.yuweiwangluo.fragment;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.activity.VenueBookActivity;
import com.bocai.yuweiwangluo.base.BaseFragment;
import com.bocai.yuweiwangluo.bean.HomeBean;
import com.bocai.yuweiwangluo.utils.ImageLoaderUtil;
import com.bocai.yuweiwangluo.utils.UrlData;

import java.text.DecimalFormat;

import butterknife.ButterKnife;


/**
 * Created by admin on 2015/9/16.
 */
public class HotVenueFrag extends BaseFragment implements View.OnClickListener {
    private View view;
    private LinearLayout ll_home_recommend_venue1;
    private ImageView ivVenue1Img;
    private TextView tvVenue1Name;
    private TextView tvVenue1Distance;
    private TextView tvVenue1Content;
    private TextView tvVenue1Money;
    private TextView tvVenue1Sold,tvMoney;
    private HomeBean.Hot datas;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.hot_venue_grag, container, false);
        initView();
        return view;
    }
    public void getData(HomeBean.Hot data){
        this.datas=data;


    }

    private void initData() {
        try{
            tvVenue1Name.setText(datas.getTitle());
            DecimalFormat df = new DecimalFormat("#0.0");
            tvVenue1Distance.setText(df.format(Double.parseDouble(datas.getMin_local()))+"km");//距离
            tvVenue1Content.setText(datas.getContent());
            tvVenue1Money.setText(Math.round(Double.parseDouble(datas.getItem_price()))+"");

            tvMoney.setText("原价"+Math.round(Double.parseDouble(datas.getPrice()))+"元");
            if(datas.getSale_num()==null){
                tvVenue1Sold.setText("已售 0");
            }else{

                tvVenue1Sold.setText("已售 " + datas.getSale_num());
            }
            ImageLoaderUtil.loaderImageDefault(UrlData.IMAGEURL + datas.getPic(), ivVenue1Img);
        }catch (Exception e){}


    }

    private void initView() {
        ButterKnife.bind(this, view);
        ll_home_recommend_venue1 = (LinearLayout)view.findViewById(R.id.ll_home_recommend_venue1);
        ivVenue1Img=(ImageView)view.findViewById(R.id.iv_home_recommend_venue1_img);
        tvVenue1Name=(TextView)view.findViewById(R.id.tv_home_recommend_venue1_name);
        tvVenue1Distance=(TextView)view.findViewById(R.id.tv_home_recommend_venue1_distance);
        tvVenue1Content=(TextView)view.findViewById(R.id.tv_home_recommend_venue1_content);
        tvVenue1Money=(TextView)view.findViewById(R.id.tv_home_recommend_venue1_money);
        tvVenue1Sold=(TextView)view.findViewById(R.id.tv_home_recommend_venue1_sold);
        tvMoney=(TextView)view.findViewById(R.id.tv_money);
        tvMoney.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );//设置中间横线
        initEvent();
        initData();
    }

    private void initEvent() {
        ll_home_recommend_venue1.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id. ll_home_recommend_venue1:
                Intent intent=new Intent(getActivity(), VenueBookActivity.class);
                intent.putExtra("id", datas.getId());
                intent.putExtra("title",datas.getTitle());
                intent.putExtra("content",datas.getContent());
                intent.putExtra("local_x",datas.getLocal_x());
                intent.putExtra("local_y",datas.getLocal_y());
                startActivity(intent);
                break;

        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
